import React from 'react';
import { useSelector, useDispatch } from 'react-redux'
import { addCount, jianCount } from '../../store-rtk'

const Fun1 = () => {
    // 获取仓库中的数据
    const state = useSelector((state) => state)
    const dispatch = useDispatch()
    console.log('state', state);
    return (
        <div>
            <p>函数组件中操作rtk定义的store仓库数据</p>
            <p>
                <button onClick={
                    () => {
                        dispatch(addCount())
                    }
                }>+1</button>
                <span>{state.count}</span>
                <button onClick={
                    () => {
                        dispatch(jianCount(10))
                    }
                }>-10</button>
            </p>
        </div>
    );
}

export default Fun1;
